<template>
  <div class="merchandise-page">
    <!-- 滚动通知 -->
    <div class="notice-banner">
      <div class="notice-icon">📢</div>
      <div class="notice-content">
        <div class="scrolling-text">
            温馨提示：商品由正规渠道销售，支持7天无理由退货，购买请认准正品标识。展馆周边商品限时销售 | 高迪建筑艺术收藏 | 正品授权商品 | 7天无理由退货 | 收藏建筑大师的艺术之美
        </div>
      </div>
    </div>

    <!-- 商品列表 -->
    <div class="merchandise-container">
      <div class="merchandise-grid">
        <div class="merchandise-item" v-for="(item, index) in merchandiseItems" :key="index">
          <div class="merchandise-card">
            <div class="merchandise-image">
              <div class="image-container" v-if="item.hasImage">
                <img 
                  :src="getImageUrl(item.imagePath)" 
                  :alt="item.title"
                  class="product-image"
                  @load="onImageLoad"
                  @error="onImageError"
                />
              </div>
              <div class="image-placeholder" v-else>
                <div class="product-icon">🏛️</div>
              </div>
            </div>
            <div class="merchandise-info">
              <h4>{{ item.title }}</h4>
              <p class="product-desc">{{ item.description }}</p>
              <div class="product-features">
                <span class="feature-tag" v-for="feature in item.features" :key="feature">
                  {{ feature }}
                </span>
              </div>
              <div class="purchase-actions">
                <el-button 
                  type="primary" 
                  size="small" 
                  @click="openTaobaoLink(item.link)"
                  class="buy-btn"
                >
                  <span class="taobao-icon">🛒</span>
                  立即购买
                </el-button>
                <el-button 
                  size="small" 
                  @click="copyLink(item.link)"
                  class="copy-btn"
                >
                  复制链接
                </el-button>
              </div>
            </div>
          </div>
        </div>
      </div>
      
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'

// 展馆周边商品数据
const merchandiseItems = ref([
  {
    title: '米拉之家冰箱贴',
    description: '西班牙纪念品文艺书签高迪建筑正品礼物',
    features: ['高迪建筑', '文艺书签'],
    link: 'https://e.tb.cn/h.hbcgZ8TgYaEpWXW?tk=XCoOVIVl6t8',
    hasImage: true,
    imagePath: '/images/merchandise/gaudi-fridge-magnet.jpg'
  },
  {
    title: '圣家堂纪念品',
    description: '巴塞罗那冰箱贴书签纪念品 Sagrada圣家堂高迪装饰',
    features: ['圣家堂主题', '装饰纪念品'],
    link: 'https://e.tb.cn/h.hb7oHpNeI5kNxPU?tk=L8N5VIVOqF6',
    hasImage: true,
    imagePath: '/images/merchandise/sagrada-familia.jpg'
  }
])

// 打开淘宝链接
const openTaobaoLink = (link) => {
  try {
    window.open(link, '_blank')
    ElMessage.success('正在跳转到商品页面...')
  } catch (error) {
    ElMessage.warning('请复制链接到浏览器中打开')
    copyLink(link)
  }
}

// 复制链接到剪贴板
const copyLink = async (link) => {
  try {
    if (navigator.clipboard && window.isSecureContext) {
      await navigator.clipboard.writeText(link)
      ElMessage.success('链接已经复制到剪贴板，可在淘宝打开')
    } else {
      const textArea = document.createElement('textarea')
      textArea.value = link
      textArea.style.position = 'fixed'
      textArea.style.opacity = '0'
      document.body.appendChild(textArea)
      textArea.focus()
      textArea.select()
      
      try {
        document.execCommand('copy')
        ElMessage.success('链接已经复制到剪贴板，可在淘宝打开')
      } catch (err) {
        ElMessage.error('复制失败，请手动复制链接')
      }
      
      document.body.removeChild(textArea)
    }
  } catch (error) {
    ElMessage.error('复制失败，请手动复制链接')
  }
}

// 获取图片URL
const getImageUrl = (imagePath) => {
  // 对于public目录下的图片，直接返回路径即可
  return imagePath
}

// 图片加载事件
const onImageLoad = () => {
  console.log('图片加载完成')
}

const onImageError = () => {
  console.error('图片加载失败')
}
</script>

<style scoped>
@import '../assets/css/booking/gallery.css';

/* 页面特有样式 */
.merchandise-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  padding: 0;
}


.merchandise-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px 30px;
}

/* 展馆周边样式 */
.merchandise-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 25px;
  margin-top: 25px;
}

.merchandise-item {
  width: 100%;
}

.merchandise-card {
  background: white;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid rgba(255, 255, 255, 0.8);
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.merchandise-card:hover {
  transform: translateY(-8px) scale(1.02);
  box-shadow: 0 20px 60px rgba(102, 126, 234, 0.2);
  border-color: rgba(102, 126, 234, 0.3);
}

.merchandise-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, #667eea, #764ba2, #f093fb, #f5576c);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.merchandise-card:hover::before {
  opacity: 1;
}

.merchandise-image {
  position: relative;
  height: 200px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.image-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.product-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease;
  filter: brightness(1.1) contrast(1.1);
}

.merchandise-card:hover .product-image {
  transform: scale(1.1) rotate(1deg);
}

.image-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #667eea, #764ba2);
}

.product-icon {
  font-size: 56px;
  opacity: 0.8;
  color: white;
  text-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.merchandise-info {
  padding: 25px;
  flex: 1;
  display: flex;
  flex-direction: column;
  background: white;
  position: relative;
}

.merchandise-info::before {
  content: '';
  position: absolute;
  top: 0;
  left: 25px;
  right: 25px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(102, 126, 234, 0.3), transparent);
}

.merchandise-info h4 {
  margin: 0 0 12px 0;
  font-size: 20px;
  font-weight: bold;
  color: #333;
  line-height: 1.3;
  background: linear-gradient(135deg, #333, #555);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.product-desc {
  margin: 0 0 20px 0;
  color: #666;
  font-size: 14px;
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 1;
}

.product-features {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
}

.feature-tag {
  background: linear-gradient(135deg, #e8eaf6, #f3e5f5);
  color: #667eea;
  padding: 6px 12px;
  border-radius: 15px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid rgba(102, 126, 234, 0.2);
  transition: all 0.3s ease;
}

.feature-tag:hover {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  transform: translateY(-1px);
}

.purchase-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: auto;
}

.buy-btn {
  flex: 2;
  background: linear-gradient(135deg, #667eea, #764ba2) !important;
  border: none !important;
  border-radius: 12px !important;
  font-weight: bold !important;
  font-size: 14px !important;
  padding: 12px 20px !important;
  height: auto !important;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.3s ease !important;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.buy-btn:hover {
  background: linear-gradient(135deg, #5a6fd8, #6a4190) !important;
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
}

.taobao-icon {
  font-size: 16px;
}

.copy-btn {
  flex: 1;
  border: 1px solid #e0e6ed !important;
  color: #666 !important;
  border-radius: 12px !important;
  background: white !important;
  font-size: 13px !important;
  padding: 12px 16px !important;
  height: auto !important;
  transition: all 0.3s ease !important;
}

.copy-btn:hover {
  border-color: #667eea !important;
  color: #667eea !important;
  background: #f8f9ff !important;
  transform: translateY(-1px);
}


/* 移动端优化 */
@media (max-width: 768px) {
  .page-header {
    padding: 20px 15px 15px;
  }
  
  .page-header h2 {
    font-size: 24px;
  }
  
  .page-header p {
    font-size: 14px;
  }
  
  .merchandise-container {
    padding: 0 15px 20px;
  }

  .merchandise-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .merchandise-image {
    height: 180px;
  }

  .merchandise-info {
    padding: 20px;
  }

  .merchandise-info h4 {
    font-size: 18px;
  }

  .product-desc {
    font-size: 13px;
  }

  .buy-btn {
    font-size: 13px !important;
    padding: 10px 16px !important;
  }

  .copy-btn {
    font-size: 12px !important;
    padding: 10px 12px !important;
  }
}

@media (max-width: 480px) {
  .page-header {
    padding: 15px 10px;
  }
  
  .page-header h2 {
    font-size: 20px;
  }
  
  .page-header p {
    font-size: 13px;
  }

  .merchandise-container {
    padding: 0 10px 15px;
  }

  .merchandise-image {
    height: 160px;
  }

  .merchandise-info {
    padding: 18px;
  }

  .merchandise-info h4 {
    font-size: 16px;
  }

  .product-desc {
    font-size: 12px;
    -webkit-line-clamp: 2;
  }

  .feature-tag {
    font-size: 11px;
    padding: 4px 8px;
  }

  .purchase-actions {
    gap: 8px;
  }

  .buy-btn {
    font-size: 12px !important;
    padding: 8px 12px !important;
  }

  .copy-btn {
    font-size: 11px !important;
    padding: 8px 10px !important;
  }
}
</style> 